import org.postgresql.util.PGobject;

import java.sql.*;

public class ProDemo {

    public static void main(String[] args) throws ClassNotFoundException {
        Class.forName("org.postgresql.Driver");
        ResultSet rs = null;
        try (Connection conn = DriverManager.getConnection("jdbc:postgresql://172.16.55.175:5432/testdb", "vbadmin", "Vastdata#0730");
             CallableStatement cstmt = conn.prepareCall("{call pkg_rep_pre_rj0051.saverpt(?)}")) {

            // 必须关闭自动提交，否则 ERROR: cursor "<unnamed portal 1>" does not exist
            conn.setAutoCommit(false);
            // 注册输出参数为REF_CURSOR类型
            cstmt.setObject(1, "ddd", Types.OTHER);
            cstmt.registerOutParameter(1, Types.OTHER);
            // 执行存储过程
//            boolean execute = cstmt.execute();
            // 获取输出的游标对象
           cstmt.execute();
            String string = cstmt.getString(1);

            System.out.println(string);
//            rs = (ResultSet) cstmt.getObject(1);
            // 处理游标结果集
            while (rs.next()) {
                String str = rs.getString(1);
                System.out.println(str);
            }
            // 关闭结果集和声明
            rs.close();
        } catch (
                Exception exception) {
            exception.printStackTrace();
        }
    }

}
